const db = wx.cloud.database();
const E_sportsCircle = db.collection('campus_E-sportsCircle_userinfo');

//封装云函数的调用方法
//name 云函数的函数名
const callfun = function (name, data = {}) {
  return new Promise((resolve, reject) => {
    wx.cloud.callFunction({
      name,
      data
    }).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err);
    })
  })
}


const formatDate = date =>{
  //获取年月日
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  var realTime = [year,month,day];

  // console.log(realTime.map(formatNumber).join('-'));
  return realTime.map(formatNumber).join('-');
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  callfun,
  formatDate: formatDate,
}